Skip to content

Prevent anonymous redirects from overwriting Authelia sessions - #635

Open
MeiXu6693 wants to merge 1 commit into
linuxserver:masterfrom
MeiXu6693:fix/authelia-anonymous-cookie-race
Open

MeiXu6693 wants to merge 1 commit into
linuxserver:masterfrom
MeiXu6693:fix/authelia-anonymous-cookie-race

Conversation

@MeiXu6693

@MeiXu6693 MeiXu6693 commented Oct 29, 2026 •

Copy link
Copy Markdown
  • I have read the contributing guideline and understand the modifications.

  • An LLM assisted me in writing the code or text for this PR

  • An LLM agent wrote the code or text for this PR

Description:

Stop copying the Authelia auth-request Set-Cookie into the named 401 redirect. An anonymous request that completes after a successful portal login can otherwise replace the newly authenticated cookie with the earlier anonymous session. Portal responses still set their own cookies, and the authentication policy is unchanged.

Benefits of this PR and context:

This addresses a session race in the shared SWAG Authelia sample, not an application-specific change. Existing users must update authelia-server.conf to pick up the change. Closes #634.

I reviewed #366: it addressed add_header inheritance and subfolder compatibility. This change leaves the auth subrequest and portal routing intact. In the tested fixture, the redirected response also regains the inherited HSTS header.

How Has This Been Tested?

On x86-64 with Docker Engine 29.8.2, the current lscr.io/linuxserver/swag:latest image (5.8.0-ls495), Authelia 4.39.28, and private disposable Docker networks with test certificates and accounts:

  • The stock configuration generated an anonymous cookie; applying it after a separate portal login changed a protected response from 200 back to 302. The candidate stopped setting the anonymous cookie and retained 200 after login.
  • A headless Chromium/Playwright test intercepted a real anonymous 302, delayed it until after portal login, and then delivered it. Stock: session cookie changed and the protected site redirected; candidate: cookie unchanged and protected site returned 200. The page containing the background request was a synthetic same-origin page.
  • With the candidate, nginx -t, first-factor login, TOTP step-up, access after the second factor, logout and rejection of the logged-out session passed. A public OIDC client completed authorization-code flow with S256 PKCE and a token exchange, an Authelia portal under /authelia/ completed a first-factor login, and a deliberately invalid session cookie was replaced by a successful portal login. With a three-second test idle timeout, expiry required reauthentication and a remembered session remained valid.
  • The test containers did not publish host ports, use real DNS, or use production accounts. The reproduction script and redacted output are in [BUG] Anonymous Authelia redirects can overwrite a newer login session #634. Other versions, passkeys and every third-party application have not been tested.

Built the committed source with docker build --no-cache --pull, using a temporary Dockerfile that adds one preceding RUN to replace the Alpine APK mirror with an HTTPS mirror because the default mirror stalled. The build also used a local HTTP proxy; the committed Dockerfile is unchanged. The resulting test image started successfully with an isolated certificate and test configuration, generated an authelia-server.conf identical to the committed sample, and passed nginx -t. It passed the headless-browser late-response test; after restart with the existing /config, anonymous access redirected without a session cookie and portal login restored access. This is not a bit-for-bit build of the unmodified Dockerfile because of the temporary mirror step.

Source / References:

OpenAI Codex (GPT-6) performed the investigation, wrote the patch and this description, and ran the tests. Human review is still needed; no human review is claimed here.

@LinuxServer-CI

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

[BUG] Anonymous Authelia redirects can overwrite a newer login session

2 participants